// packageProduct/pages/detail/index.js
import {getDetail, getWeekNv} from "../../../service/Product";
Page({

    /**
     * 页面的初始数据
     */
    data: {
        isLoading: true,
        isError: false, //加载失败
        chartList: [], //数据图表
        detail: {}
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.setData({id: options.id})
        this.getProductDetail(options.id)
    },

    /*
    * 获取产品详情
    * */
    getProductDetail: async function (id) {
        try {
            let res = await getDetail(id);
            let detail = {...res};
            let n_warning_line = detail.n_warning_line;
            let n_stop_loss_line = detail.n_stop_loss_line;
            detail.n_warning_line = n_warning_line && n_warning_line - 0 > 0 ? n_warning_line : "--";
            detail.n_stop_loss_line = n_stop_loss_line && n_stop_loss_line - 0 > 0 ? n_stop_loss_line : "--";
            await this.getNvList({c_fund_id: id});
            this.setData({detail})
        } catch (e) {
            console.error(e)
        } finally {
            this.setData({isLoading: false});
        }
    },

    /*
    * 获取净值
    * */
    getNvList: async function (data = {}) {
        let res = await getWeekNv(data);
        this.setData({chartList: res.reverse()})
    }
})